import cv2
import numpy as np

import uitls.mat2cell as m2c
def brt2img(brt, brt_aoi): # to 512*512 512*2560
    for color_idx in brt.color:
        if color_idx=='R' or color_idx=='B':
            brt_single_sub_3d = np.zeros([512, 512, 5, len(brt.gray_level)])
        elif color_idx == 'G':
            brt_single_sub_3d = np.zeros([512, 512, 10, len(brt.gray_level)])
        else:
            raise ValueError("输入数据字段异常")
        for gray_idx in range(len(brt.gray_level)):
            brt_single = brt[color_idx][...,gray_idx]
            if color_idx=='R' or color_idx=='B':
                brt_single = cv2.resize(brt_single,[512,2560])
                brt_single_sub = m2c.mat2cell(brt_single,5,1)
            elif color_idx=='G':
                brt_single = cv2.resize(brt_single, [1024, 2560])
                brt_single_sub = m2c.mat2cell(brt_single, 5, 2)
            else:
                raise ValueError("输入数据字段异常")
            # list 2 3D
            # r, c = brt_single_sub[0].shape
            # pcs = len(brt_single_sub)

            for pcs_idx in range(5):
                brt_single_sub_3d[..., pcs_idx, gray_idx] = brt_single_sub[pcs_idx]

            # inital brt(4d) d1d2:m and n, d3: pcs idx(csv2img), d4:gray level
        brt_aoi[color_idx] = brt_single_sub_3d
    return brt_aoi